﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_GetBBSForumItem]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_GetBBSForumItem];
GO
CREATE PROCEDURE [dbo].[sproc_GetBBSForumItem]
    @board_id int
/*

=====================================================
功能:    得到该版块的所有帖子
参数:
    @board_id int        :    该版块ID
=====================================================

*/
AS
select *,COALESCE(last_replay_time,send_time)
    from uds_bbs_forumitem 
    where  (sysbulletin = 1)

union all

SELECT *,COALESCE(last_replay_time,send_time)
    FROM uds_bbs_forumitem b
    WHERE board_id = @board_id AND (bulletin = 1 ) 
    

union all

SELECT *,COALESCE(last_replay_time,send_time)
    FROM uds_bbs_forumitem c
    WHERE board_id = @board_id AND (bulletin = 0 OR bulletin IS NULL) AND (sysbulletin = 0 OR sysbulletin IS NULL)
    
ORDER BY sysbulletin desc,bulletin desc,COALESCE(last_replay_time,send_time) DESC